﻿using System;
using Medianamik.Core.Security;

namespace Medianamik.Core.Action
{
    public class UserHandler : IActionHandler 
    {
        public void Initialize(ActionManager events)
        {
            events.BeforeDeleteNode += DeleteUser;
        }

        private void DeleteUser(ActionEventArgs<Node> args)
        {
            if (args.Item.NodeType.ID.Equals(MedianamikTypes.MedianamikProfile))
            {
                SecurityManager.DeleteUser(args.Item.DefaultInstance.Properties["User"].GetValue<Guid>());
            }
        }

        public string Description
        {
            get { return "Deletes user after user profile is deleted."; }
        }
    }
}
